// pages/myReservation/index.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tabData: [],
    orderStatusMap: {
      "1": "待支付",
      "2": "已支付",
      "3": "已完成",
      "-1": "已取消",
    },
    tabList: [
      {
        key: "all",
        label: "全部",
      },
      {
        key: "pending",
        label: "待支付",
      },
      {
        key: "progress",
        label: "进行中",
      },
      {
        key: "completed",
        label: "已完成",
      },
    ],
    activeKey: "all",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad() {
    this.queryAllList();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},
  handleTabChange({ detail }: any) {
    const map: any = {
      all: this.queryAllList,
      pending: this.pendingPayment,
      progress: this.paid,
      completed: this.completed,
    };
    map[detail.value]();
    this.setData({
      activeKey: detail.value,
    });
  },
  //全部
  async queryAllList() {
    try {
      const res = await getApp().request({
        path: "/s/o/listAllOrders",
        method: "GET",
      });
      this.setData({
        tabData: res,
      });
    } finally {
    }
  },
  //待支付
  async pendingPayment() {
    try {
      const res = await getApp().request({
        path: "/s/o/listAllToPaiedOrder",
        method: "GET",
      });
      this.setData({
        tabData: res,
      });
    } finally {
    }
  },

  //进行中、已支付
  async paid() {
    try {
      const res = await getApp().request({
        path: "/s/o/listAllPaiedOrder",
        method: "GET",
      });
      this.setData({
        tabData: res,
      });
    } finally {
    }
  },
  //已完成
  async completed() {
    try {
      const res = await getApp().request({
        path: "/s/o/listAllOverOrder",
        method: "GET",
      });
      this.setData({
        tabData: res,
      });
    } finally {
    }
  },

  scrolltolower(e) {},
  handleBack(e) {
    const { id } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/orderDetails/index?orderId=${id}`,
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
